import {
	defineStore
} from 'pinia'
import {
	ref
} from 'vue'
import {
	getUserInfoSerive
} from '@/api/user'

// 用户模块
export const useUserStore = defineStore(
	'user',
	() => {
		// const token = ref('eyJhbGciOiJIUzUxMiJ9.eyJtaW5pX2xvZ2luX3VzZXJfa2V5IjoiMTAwNGMyYTItYWM0Mi00OWIwLTk5MTAtZDk0Y2YyOTEyZjdmIn0.ZlOfz0aiJ59ljR9IOu6qOZQVkO19nJOf4BLRsoR_XencVLeJYlPPGtCEHDEKHr_Q8NF9ydEVOyJIY6oa8Sisdw') // 定义 token
		const token = ref('')
		const setToken = (t) => (token.value = t) // 设置 token
		const removeToken = () => (token.value = '') // 设置 token
		const user = ref({})
		const getUser = async () => {
			const res = await getUserInfoSerive() //获取数据
			if (res.code === 200) {
				user.value = res.data
			}
		}
		const setUser = (obj) => {
			console.log(obj, "++___")
			user.value = obj
		}
		return {
			token,
			setToken,
			removeToken,
			user,
			getUser,
			setUser
		}
	}
)